<?php
namespace app\admin\controller;

use think\Controller;
use think\Request;

class Set extends Base
{
    public function update(Request $request)
    {
        $inputdata=input();
        $id=input('id');
        unset($inputdata['file']);
        $res=db('basic')->where(['id'=>$id])->update($inputdata);
       // dump($res);exit();
        if ($res){
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }
    public function upload(){
        // 获取表单上传文件 例如上传了001.jpg
        $file = request()->file('file');
        // 移动到框架应用根目录/uploads/ 目录下
        $info = $file->move('./upload/');
        if($info){
            $image = \think\Image::open($info);
// 按照原图的比例生成一个最大为150*150的缩略图并保存为thumb.png
            $image->thumb(150,150)->save("./upload/".$info->getSaveName());
            $path = 'http://jiaoyu.com/upload/'.$info->getSaveName();
            return["code"=>"0","msg"=>"上传成功","data"=>$path];
        }else{
            return["code"=>"1","msg"=>"失败","data"=>""];
        }
    }
    public function indexes(){
        $where = [];
        $where['type']=1;
        $find = db("accounts")->where($where)->find();
        $this->assign('find',$find);
        return $this->fetch();
    }
    public function add()
    {
        $inputdata=input();
        $id=input('id');
        unset($inputdata['file']);
        $res=db('accounts')->where(['id'=>$id])->update($inputdata);
        // dump($res);exit();
        if ($res){
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }
    public function pay(){
        $where = [];
        $where['type']=1;
        $find = db("payment")->where($where)->find();
        $this->assign('find',$find);
        return $this->fetch();
    }
    public function pay_update(){
        $inputdata=input();
        $id=input('id');
        unset($inputdata['file']);
        $res=db('payment')->where(['id'=>$id])->update($inputdata);
        if ($res){
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }
    public function payes(){
        $where = [];
        $where['type']=1;
        $find = db("alicloud_configuration")->where($where)->find();
        $this->assign('find',$find);
        return $this->fetch();
    }
    public function payes_update(){
        $inputdata=input();
        $id=input('id');
        unset($inputdata['file']);
        $res=db('alicloud_configuration')->where(['id'=>$id])->update($inputdata);
        // dump($res);exit();
        if ($res){
            $this->success('修改成功');
        }else{
            $this->error('修改失败');
        }
    }
}